package com.ruoyi.web.controller.consume;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.VipDetail;
import com.ruoyi.service.IVipDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消费记录Controller
 *
 * @author ruoyi
 * @date 2020-08-10
 */
@Controller
@RequestMapping("/ruoyi/detail")
public class VipDetailController extends BaseController {
    private String prefix = "ruoyi/detail";

    @Autowired
    private IVipDetailService vipDetailService;

    @RequiresPermissions("ruoyi:detail:view")
    @GetMapping("/list/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("id",id);
        return prefix + "/detail";
    }

    /**
     * 查询消费记录列表
     */
    @RequiresPermissions("ruoyi:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Long id) {
        startPage();
        List<VipDetail> list = vipDetailService.selectVipDetailLists(id);
        return getDataTable(list);
    }

    /**
     * 导出消费记录列表
     */
    @RequiresPermissions("ruoyi:detail:export")
    @Log(title = "消费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VipDetail vipDetail) {
        List<VipDetail> list = vipDetailService.selectVipDetailList(vipDetail);
        ExcelUtil<VipDetail> util = new ExcelUtil<VipDetail>(VipDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 新增消费记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存消费记录
     */
    @RequiresPermissions("ruoyi:detail:add")
    @Log(title = "消费记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VipDetail vipDetail) {
        return toAjax(vipDetailService.insertVipDetail(vipDetail));
    }

    /**
     * 修改消费记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        VipDetail vipDetail = vipDetailService.selectVipDetailById(id);
        mmap.put("vipDetail", vipDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存消费记录
     */
    @RequiresPermissions("ruoyi:detail:edit")
    @Log(title = "消费记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VipDetail vipDetail) {
        return toAjax(vipDetailService.updateVipDetail(vipDetail));
    }

    /**
     * 删除消费记录
     */
    @RequiresPermissions("ruoyi:detail:remove")
    @Log(title = "消费记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(vipDetailService.deleteVipDetailByIds(ids));
    }
}
